package com.ofek.eventos.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerializationUtils {
 public static boolean serialize(final Object o,final File f){
	 ObjectOutputStream so = null;
	 try {
	     final BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(f));
	     so = new ObjectOutputStream(bo);
	     so.writeObject(o);
	     so.flush();
	 } catch (final Exception e) {
		 e.printStackTrace();
		 return false;
	 } finally {
		 try {
			if (so!=null) so.close();
		} catch (final IOException e) {
			e.printStackTrace();
		}
	 }
	 return true;
 }
 public static Object deserialize(final File main) {
	 ObjectInputStream si = null;
	try {
	     final BufferedInputStream bi = new BufferedInputStream(new FileInputStream(main));
	     si = new ObjectInputStream(bi);
	     return si.readObject();
	 } catch (final Exception e) {
	     e.printStackTrace();
	 } finally {
		 try {
			 if (si!=null) si.close();
		} catch (final IOException e) {
			e.printStackTrace();
		}
	 }
	return null;
 }
}
